﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace NGUYENTHANHDONG.OOP.Inhertance___Polimophism.EXCERCISES.EXCERCISE_01
{
    public partial class Calculator : Form
    {
        public Calculator()
        {
            InitializeComponent();
        }

        private void Calculator_Load(object sender, EventArgs e)
        {
            cmbPhepToan.Items.Add("Cộng");
            cmbPhepToan.Items.Add("Trừ");
            cmbPhepToan.Items.Add("Nhân");
            cmbPhepToan.Items.Add("Chia");
            cmbPhepToan.SelectedIndex = 0;
        }

        private void btnXacNhan_Click(object sender, EventArgs e)
        {
            errorProvider1.Clear();

            if(string.IsNullOrEmpty(txtSoa.Text))
            {
                errorProvider1.SetError(txtSoa, "Khong dc de trong !!");
                txtSoa.Focus();
            }
            else if(string.IsNullOrEmpty(txtSob.Text))
            {
                errorProvider1.SetError(txtSob, "Khong dc de trong !!");
                txtSob.Focus();
            }
            else
            {
                ClassUser objUser = new ClassUser();

                double a = double.Parse(txtSoa.Text);

                double a2 = double.Parse(txtSoa.Text);
                int a1 = (int)a2;

                double b = double.Parse(txtSob.Text);
                double b2 = double.Parse(txtSob.Text);
               
                int b1 = (int)b2;


                if(a - a1 == 0 && b - b1 == 0)
                {
                    if(cmbPhepToan.Text == "Cộng")
                    {
                        lsbKetQua.Items.Add( objUser.Cong(int.Parse(txtSoa.Text), int.Parse(txtSob.Text)) + " ");
                    }
                    else if (cmbPhepToan.Text == "Trừ")
                    {
                        lsbKetQua.Items.Add(objUser.Tru(int.Parse(txtSoa.Text), int.Parse(txtSob.Text)) + " "); ;
                    }
                    else if (cmbPhepToan.Text == "Nhân")
                    {
                        lsbKetQua.Items.Add( objUser.Nhan(int.Parse(txtSoa.Text), int.Parse(txtSob.Text)) + " ");
                    }
                    else if (cmbPhepToan.Text == "Chia")
                    {
                        lsbKetQua.Items.Add( objUser.Chia(int.Parse(txtSoa.Text), int.Parse(txtSob.Text)) + " ");
                    }
                }
                else if(a - a1 != 0 && b - b1 != 0)
                {
                    if (cmbPhepToan.Text == "Cộng")
                    {
                        lsbKetQua.Items.Add(objUser.Cong(float.Parse(txtSoa.Text), float.Parse(txtSob.Text)) + " ");
                    }
                    else if (cmbPhepToan.Text == "Trừ")
                    {
                        lsbKetQua.Items.Add(objUser.Tru(float.Parse(txtSoa.Text), float.Parse(txtSob.Text)) + " ");
                    }
                    else if (cmbPhepToan.Text == "Nhân")
                    {
                        lsbKetQua.Items.Add(objUser.Nhan(float.Parse(txtSoa.Text), float.Parse(txtSob.Text)) + " ");
                    }
                    else if (cmbPhepToan.Text == "Chia")
                    {
                        lsbKetQua.Items.Add(objUser.Chia(float.Parse(txtSoa.Text), float.Parse(txtSob.Text)) + " ");
                    }
                }

            }
        }
    }
}
